package cn.gson.springboot.model.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gson.springboot.model.dao.CkDAO;
import cn.gson.springboot.model.dao.RedetaiDAO;
import cn.gson.springboot.model.dao.ReturnyfDAO;
import cn.gson.springboot.model.mapper.ZhichuMapper;
import cn.gson.springboot.model.pojos.Apply;
import cn.gson.springboot.model.pojos.Applydetai;
import cn.gson.springboot.model.pojos.Ck;
import cn.gson.springboot.model.pojos.DrugsYk;
import cn.gson.springboot.model.pojos.PrescriptionPx;
import cn.gson.springboot.model.pojos.Redetai;
import cn.gson.springboot.model.pojos.ReturnYf;
import cn.gson.springboot.model.pojos.Spenddetai;
import cn.gson.springboot.model.vo.ChufangVO;
import cn.gson.springboot.model.vo.TuihuoyfVO;

@Service
@Transactional(rollbackFor=Exception.class)
public class ZhichuService {
	@Autowired
	private ZhichuMapper tm;
	@Autowired
	private ReturnyfDAO rm;
	@Autowired
	private RedetaiDAO dm;
	@Autowired
	private CkDAO ck;
	//查询所有药品
		public List<Map<String,Object>> cxsy() {
			List<Map<String,Object>> ll= tm.cxsy(); 
			return ll;
		}
		public List<Map<String,Object>> cxypsy(int a) {
			List<Map<String,Object>> ll= tm.cxypsy(a); 
			return ll;
		}
		public List<Map<String,Object>> ylkcx(String a) {
			List<Map<String,Object>> ll= tm.ylkcx(a); 
			return ll;
		}
		public List<Map<String,Object>> bmsy() {
			List<Map<String,Object>> ll= tm.bmsy(); 
			return ll;
		}
		public List<Map<String,Object>> bmidcx(String a) {
			List<Map<String,Object>> ll= tm.bmidcx(a); 
			return ll;
		}
		public List<Map<String,Object>> bmypsy(int a) {
			List<Map<String,Object>> ll= tm.bmypsy(a); 
			return ll;
		}
		public void tjxq(TuihuoyfVO svo) {
			ReturnYf re=svo.getOrder();
			ReturnYf save=rm.save(re);

			Redetai dd=svo.getDetails();
			dd.setReturnYf(save);
			dd.setYppc(svo.getDetails().getYppc());
			dd.setDrugsYk(svo.getDetails().getDrugsYk());
			dd.setRedetaiNumberYf(svo.getDetails().getRedetaiNumberYf());
			dd.setRedetaiMoneyYf(svo.getDetails().getRedetaiMoneyYf());
			
			Ck c=ck.kmpccx(svo.getDetails().getDrugsYk().getDrugId(),svo.getDetails().getYppc());
			System.out.println(c.getDrugs_Stock_kc()+"--------");
			c.setDrugs_Stock_kc(c.getDrugs_Stock_kc()+svo.getDetails().getRedetaiNumberYf());
			ck.save(c);
			System.out.println("数量修改成功");
			dm.save(dd);
			
		}
}
